package com.ming.transaction.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 公共返回对象
 * @author: Chenming
 * @date 2023/5/3 11:33
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result {
    private long code;
    private String message;
    private Object obj;

    /**
     * 返回成功信息
     * @param message
     * @return
     */
    public static Result success(String message){
        return new Result(200,message,null);
    }

    /**
     * 返回空信息
     * @return
     */
    public static Result success(){
        return new Result(200,null,null);
    }

    /**
     * 返回成功信息和对象数据
     * @param message
     * @param obj
     * @return
     */
    public static Result success(String message,Object obj){
        return new Result(200,message,obj);
    }

    /**
     * 返回失败结果
     * @param message
     * @return
     */
    public static Result fail(String message){
        return new Result(500,message,null);
    }

    /**
     * 失败返回编码和信息
     * @param code
     * @param message
     * @return
     */
    public static Result fail(long code,String message) {
        return new Result(code, message, null);
    }


    /**
     * 返回无参错误
     * @return
     */
    public static Result fail(){
        return new Result(500,"未知错误",null);
    }

}
